package pl.enigmatic.math.graph;

import pl.enigmatic.objects.WrapperObject;


public class AttachedSingleParentedLeaf<B, L extends AttachedSingleParentedLeaf<B, L, T>, T extends AttachedSingleParentedLeafTree<L, ?, T>> extends
		WrapperObject<B> {

	T parent = null;

	public AttachedSingleParentedLeaf(final B base) {
		super(base);
	}

	protected void onParentChanged(final T oldParent) {}

	@SuppressWarnings("unchecked")
	public void setParent(final T parent) {
		AttachedSingleParentedLeafTree.setParentChildRelationship(parent, (L) this, -1);
	}

	public T getParent() {
		return parent;
	}

	public boolean hasParent() {
		return parent != null;
	}

	public int getDepth() {
		return hasParent() ? parent.getDepth() + 1 : 0;
	}

}
